<?php

/**
 * A simple concrete implimentation of Log_XML_String.
 * 
 * PHP version 5.
 * 
 * @category Logging
 * @package  Log
 * @author   Michael Peter 'Vladimyr' Gower <designatevoid@gmail.com>
 * @author   "ilgarm" <ilgarm@azeronline.com>
 * @author   Jon Parise <jon@php.net>
 * @author   Roman Neuhauser <neuhauser@bellavista.cz>
 * @license  http://www.apache.org/licenses/LICENSE-2.0  Apache License 2.0
 * @link     http://pear.php.net/pepr/pepr-proposal-show.php?id=487
 */

/**
 * Require the base class.
 */
require_once 'Log/XML/String.php';

/**
 * The simplest, fastest implimentation of Log_XML_String you can do.
 *
 * The log will have this format:
 * <SimpleLog>
 *  <Header>
 *  </Header>
 *  <LogEntries>
 *   <LogEntry>
 *   </LogEntry>
 *  </LogEntries>
 * </SimpleLog>
 *
 * @category Logging
 * @package  Log
 * @author   Michael Peter 'Vladimyr' Gower <designatevoid@gmail.com>
 * @license  http://www.apache.org/licenses/LICENSE-2.0  Apache License 2.0
 * @link     http://pear.php.net/pepr/pepr-proposal-show.php?id=487
 */
class Log_XML_String_Simple extends Log_XML_String
{
    /**
     * Add the header to the xml file.
     *
     * @return boolean true on success, false on failure
     */
    protected function createHeader()
    {
        // add root SimpleLog node
        // TODO: Implement this class!
        //$node_root = $this->appendElement($this->domDocument, 'SimpleLog');
        if(!$this->open()) {
            throw new Log_XML_Exception();
        }
        $header = <<<HEADER
          <SimpleLog>
           <Header>
           </Header>
           <LogEntries>
            <LogEntry>
            </LogEntry>
           </LogEntries>
          </SimpleLog>
HEADER;
        $header = trim($header);
        $header = preg_replace('/\s+/', '', $header);
        $writeReturn = !fwrite($this->fileHandle, $header);
        if(!$writeReturn) {
            return false;
        }
        // flush all
        $this->flush();
        
        return true;
    }


    /**
     * Creates the log entry in the xml file.
     *
     * @param mixed $message the message to log
     *
     * @return boolean true on success, false on failure
     */
    protected function createLogEntry($message)
    {
        // get the root node
        //$node_root = $this->domDocument
        //                  ->getElementsByTagName('SimpleLog')->item(0);

        // add SimpleLog->Message
        //$this->appendElement($node_root, 'Message', $message);

        // flush
        //$this->flush();

        return true;
    }


    protected function appendElement($node_parent, $string_name, $value = null)
    {
//        $node_child = $this->domDocument->createElement($string_name);
//        $node_parent->appendChild($node_child);
//        if ($value !== null) { // add text node
//            $node_childText = $this->domDocument->createTextNode($value);
//            $node_child->appendChild($node_childText);
//        }
//        return $node_child;
    }
}

?>